package com.lc.qianrenshiye.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/28.
 */
@HttpInlet(Conn.NEWS_NEWS_LIST)
public class MessageListGet extends BaseAsyGet<MessageListGet.MessageListEntity> {

    public MessageListGet(AsyCallBack<MessageListEntity> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected MessageListEntity parser(JSONObject object) throws Exception {

        TOAST = object.optString("message");

        if (object.optInt("code") == 200) {

            MessageListEntity messageListEntity = new MessageListEntity();

            JSONArray arrayMain = object.optJSONArray("data");

            for (int i = 0; i < arrayMain.length(); i++) {

                JSONObject objectItem = arrayMain.optJSONObject(i);

                JSONArray arrayItem = objectItem.optJSONArray("list");

                for (int j = 0; j < arrayItem.length(); j++) {

                    MessageEntity messageEntity = new MessageEntity();

                    JSONObject messageObject = arrayItem.optJSONObject(j);

                    if (j == 0) {

                        messageEntity.time = objectItem.optString("time");

                    } else {

                        messageEntity.time = "";

                    }

                    messageEntity.id = messageObject.optString("id");
                    messageEntity.title = messageObject.optString("title");

                    messageListEntity.messageEntityList.add(messageEntity);

                }

            }

            return messageListEntity;

        }


        return null;
    }

    public static class MessageListEntity {

        public List<MessageEntity> messageEntityList = new ArrayList<>();
    }

    public static class MessageEntity {

        public String id,title,time;

    }

}
